package com.yan.common.mq.xml;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by yanl_ on 2018/5/4.
 */
@Service
public class Producer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void test() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("testxmlxmlxml", "yan");
        try {
            Message message = MessageBuilder.withBody(JSON.toJSONString(map).getBytes("utf-8")).build();
            rabbitTemplate.send("exchange.lotus", "rkey.payment.notify", message);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

}